<!--景点门票、门票套餐、游玩项目-->
<template>
	<view class="ticket-card bg-white" v-if="data">
		<view class="ticket-title">{{ data.ticket_group_name }}</view>
		<view class="coupon-line"></view>
		<view class="ticket-content c-grey-86" v-for="(item, index) in data.spus" :key="index">
			<view class="flex-col">
				<view class="fs-28 font-500 c-black-_9 mb-12 text-2-ellipsis">{{ item.display_name }}</view>
				<view class="mb-12" v-if="item.age_rules" v-for="(age, index) in item.age_rules" :key="index">
					<text>{{ age }}</text>
				</view>
			</view>
			<view class="flex flex-nowrap mb-12 tag-wrap">
				<zjy-labels :data="item.sale_tips" key-name="title" key-bg-color="border_color" />
			</view>
			<view class="ticket-info space-between">
				<view class="flex-j flex-col">
					<!-- 销量和预订信息 -->
					<view class="sale-info mb-12 flex-a">
						<view class="">已售{{ formatSaleQuantity(item.sale_quantity) }}</view>
						<view class="divider"></view>
						<text class="notice" @click="handleClickBookingRule(item)">预订须知</text>
						<image :src="imgBaseUrl + 'icon-right.png'" class="icon-16 ml-4 mt-2"></image>
					</view>

					<!-- 推广佣金 -->
					<view
						class="commission-tag"
						:style="{
							backgroundImage: `url(${imgBaseUrl + 'commission-bg.png'})`,
							backgroundSize: '100% 100%',
						}"
					>
						<text class="commission-text">推广佣金¥22</text>
					</view>

					<!-- 店铺信息 -->
					<view class="shop-info flex-a">
						<image
							class="shop-icon"
							:src="imgBaseUrl + 'self-operated-icon.png'"
							v-if="item.store_self_employed"
						/>
						<text class="c-grey-86 fs-22">{{ subString(item.store_name, 8) }}</text>
						<image :src="imgBaseUrl + 'right-icon.png'" class="icon-16 ml-4 mt-2"></image>
					</view>
				</view>
				<!-- 价格和订购区域 -->
				<view class="price-action">
					<view class="price-info">
						<view class="price-start">
							<text class="price-symbol">¥</text>
							<text class="price">{{ formatAmount(item.lowest_price_in_cent) }}</text>
							<text class="price-unit">起</text>
						</view>

						<!-- 优惠信息 -->
						<view class="discount flex-a" style="display: none">
							<text class="original">¥198</text>
							<text class="discount-text">优惠¥72</text>
						</view>
					</view>

					<!-- 订购按钮 -->
					<view
						class="order-btn flex-c"
						:class="{ disabled: item.sold_out === true || item.saleable == false }"
						@click.stop="handleBookingClick(item)"
					>
						<template v-if="item.sold_out">售罄</template>
						<template v-else>订</template>
					</view>
				</view>
			</view>
		</view>
		<!--		<view class="view-more" v-if="data.spus.length > 3 && showMore === false" @click.stop="showMore = true">
			<view class="text">查看更多{{ data.spus.length - 3 }}个</view>
			<image :src="imgBaseUrl + 'icon-dropdown.png'" class="icon-16"></image>
		</view>-->
	</view>
</template>

<script setup lang="ts">
import { inject } from "vue"
import { formatSaleQuantity, subString } from "@/mixins/mixins"
import ZjyLabels from "@/components/zjy-labels.vue"
import { formatAmount } from "@/utils/tools"
const imgBaseUrl = inject("imgBaseUrl")

const props = defineProps({
	data: {
		type: Object,
		default: () => null,
	},
})
const emit = defineEmits(["handleBooking", "changeBookingTipsShow"])

const showMore = ref(false)
// 点击预订须知
const handleClickBookingRule = (data) => {
	emit("changeBookingTipsShow", { show: true, data })
}
// 点击订
const handleBookingClick = (item) => {
	emit("handleBooking", item)
}
</script>

<style lang="scss" scoped>
.ticket-card {
	padding: 0 0 32rpx;
	margin-top: 16rpx;
	display: flex;
	flex-direction: column;
	border-radius: 16rpx;

	.ticket-title {
		padding: 32rpx 32rpx 28rpx;
		font-size: 32rpx;
		font-weight: 600;
	}

	.coupon-line {
		border: 2rpx dashed #e9eaee;
		position: relative;
		&::before {
			content: "";
			display: block;
			position: absolute;
			top: -10rpx;
			left: -10rpx;
			background: $grey;
			width: 20rpx;
			height: 20rpx;
			border-radius: 50%;
		}
		&::after {
			content: "";
			display: block;
			position: absolute;
			top: -10rpx;
			right: -10rpx;
			background: $grey;
			width: 20rpx;
			height: 20rpx;
			border-radius: 50%;
		}
	}

	.ticket-content {
		padding: 0 24rpx;
		margin-top: 40rpx;
		padding-bottom: 32rpx;
		position: relative;
		&:after {
			content: "";
			display: block;
			position: absolute;
			bottom: 0;
			left: 24rpx;
			right: 24rpx;
			height: 1rpx;
			background: $c-grey-e5;
		}
		&:last-child {
			padding-bottom: 0;
			&:after {
				display: none;
			}
		}

		.tag-wrap {
			height: 40rpx;
			overflow: hidden;
		}
		.ticket-info {
			flex: 1;

			.sale-info {
				.divider {
					width: 1rpx;
					height: 20rpx;
					background: $c-grey-e5;
					margin: 0 12rpx;
				}
			}

			.commission-tag {
				align-items: center;
				display: inline-flex;
				margin-bottom: 12rpx;
				width: 210rpx;
				height: 36rpx;
				padding-left: 40rpx;

				.commission-text {
					font-size: 20rpx;
					color: #f53f3f;
				}
			}

			.shop-info {
				.shop-icon {
					width: 68rpx;
					height: 28rpx;
					margin-right: 4rpx;
					margin-top: 3rpx;
				}
			}
		}

		.price-action {
			display: flex;
			align-items: flex-end;
			justify-content: space-between;

			.price-info {
				display: flex;
				flex-direction: column;
				justify-content: center;
				height: 84rpx;
				align-items: flex-end;
				margin-right: 16rpx;

				.price-start {
					.price-symbol {
						color: #fe4f2f;
					}

					.price {
						font-size: 32rpx;
						font-weight: 900;
						color: #fe4f2f;
					}

					.price-unit {
						color: #fa541c;
					}
				}

				.discount {
					.original {
						text-decoration: line-through;
						margin-right: 8rpx;
						color: $c-grey-c9;
					}

					.discount-text {
						background: url($imgBaseUrl + "discount-bg.png") no-repeat center center;
						background-size: cover;
						color: #f53f3f;
						font-size: 20rpx;
						padding: 2rpx 6rpx;
					}
				}
			}

			.order-btn {
				width: 84rpx;
				height: 84rpx;
				background: linear-gradient(90deg, #ff7229 0%, #ff5416 100%);
				border-radius: 16rpx;
				font-size: 32rpx;
				color: #fff;
				&.disabled {
					background: $c-grey-e5;
					color: $c-grey-86;
				}
			}
		}
	}

	.view-more {
		display: flex;
		justify-content: center;
		align-items: center;
		background: #f1f2f5;
		padding: 12rpx 0;
		margin: 0 24rpx;

		.text {
			color: #4e5969;
			margin-right: 4rpx;
		}
	}
}
</style>
